/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eproject_sem2;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author ZER0
 */
@SuppressWarnings("serial")
public class Prices_by_Parce extends javax.swing.JFrame {

    ListOfPrice_Sever a = new ListOfPrice_Sever();
    VotesSent_Sever s = new VotesSent_Sever();

    public JInternalFrame getItnfPriceByParce() {
        return itnfPriceByParce;
    }

    /**
     * Creates new form Prices_by_Parce
     */
    public Prices_by_Parce() {
        initComponents();
        tfTypeParceIDE1.setEditable(false);
        tfTypeParceIDE1.setText(s.CreateID("List_of_Parce", "P"));
        a.ShowTable("STTP", "TypeParceID", "TypeName", "PriceOfTypeParce", "List_of_Parce", tbPriceByParceE);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        itnfPriceByParce = new javax.swing.JInternalFrame();
        jpPIBParceE = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tbPriceByParceE = new javax.swing.JTable();
        jpUpdatePriceE4 = new javax.swing.JPanel();
        lbTypeParceIDSearchE1 = new javax.swing.JLabel();
        tfTypeParceIDE1 = new javax.swing.JTextField();
        lbTypeNameE1 = new javax.swing.JLabel();
        tfTypeNameE1 = new javax.swing.JTextField();
        lbPriceOfTypeParceE1 = new javax.swing.JLabel();
        tfPriceOfTypeParceE1 = new javax.swing.JTextField();
        btEditE4 = new javax.swing.JButton();
        btResetE4 = new javax.swing.JButton();
        btExitE4 = new javax.swing.JButton();
        btAddE5 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        itnfPriceByParce.setClosable(true);
        itnfPriceByParce.setVisible(true);

        jpPIBParceE.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1), "Price information by parce", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        tbPriceByParceE.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "STTP", "TypeParceID", "TypeName", "PriceOfTypeParce"
            }
        ));
        tbPriceByParceE.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbPriceByParceEMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(tbPriceByParceE);

        javax.swing.GroupLayout jpPIBParceELayout = new javax.swing.GroupLayout(jpPIBParceE);
        jpPIBParceE.setLayout(jpPIBParceELayout);
        jpPIBParceELayout.setHorizontalGroup(
            jpPIBParceELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpPIBParceELayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3)
                .addContainerGap())
        );
        jpPIBParceELayout.setVerticalGroup(
            jpPIBParceELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpPIBParceELayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE))
        );

        jpUpdatePriceE4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Update price", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N

        lbTypeParceIDSearchE1.setText("TypeParceID:");

        lbTypeNameE1.setText("TypeName:");

        lbPriceOfTypeParceE1.setText("PriceOfTypeParce:");

        btEditE4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/eproject_sem2/Icon/1484902.png"))); // NOI18N
        btEditE4.setText("Edit");
        btEditE4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEditE4ActionPerformed(evt);
            }
        });

        btResetE4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/eproject_sem2/Icon/images.png"))); // NOI18N
        btResetE4.setText("Reset");
        btResetE4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btResetE4ActionPerformed(evt);
            }
        });

        btExitE4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/eproject_sem2/Icon/Exit.png"))); // NOI18N
        btExitE4.setText("Exit");
        btExitE4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btExitE4ActionPerformed(evt);
            }
        });

        btAddE5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/eproject_sem2/Icon/Open-Folder-Add-icon.png"))); // NOI18N
        btAddE5.setText("ADD");
        btAddE5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAddE5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpUpdatePriceE4Layout = new javax.swing.GroupLayout(jpUpdatePriceE4);
        jpUpdatePriceE4.setLayout(jpUpdatePriceE4Layout);
        jpUpdatePriceE4Layout.setHorizontalGroup(
            jpUpdatePriceE4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpUpdatePriceE4Layout.createSequentialGroup()
                .addGroup(jpUpdatePriceE4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpUpdatePriceE4Layout.createSequentialGroup()
                        .addGap(169, 169, 169)
                        .addComponent(lbTypeParceIDSearchE1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(39, 39, 39)
                        .addComponent(tfTypeParceIDE1, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpUpdatePriceE4Layout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addComponent(lbTypeNameE1)
                        .addGap(18, 18, 18)
                        .addComponent(tfTypeNameE1, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20)
                        .addComponent(lbPriceOfTypeParceE1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tfPriceOfTypeParceE1, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(49, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpUpdatePriceE4Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(btAddE5, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btEditE4, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btResetE4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btExitE4, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(57, 57, 57))
        );
        jpUpdatePriceE4Layout.setVerticalGroup(
            jpUpdatePriceE4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpUpdatePriceE4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpUpdatePriceE4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbTypeParceIDSearchE1)
                    .addComponent(tfTypeParceIDE1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jpUpdatePriceE4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbTypeNameE1)
                    .addComponent(tfTypeNameE1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbPriceOfTypeParceE1)
                    .addComponent(tfPriceOfTypeParceE1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17)
                .addGroup(jpUpdatePriceE4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btEditE4)
                    .addComponent(btResetE4)
                    .addComponent(btExitE4)
                    .addComponent(btAddE5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout itnfPriceByParceLayout = new javax.swing.GroupLayout(itnfPriceByParce.getContentPane());
        itnfPriceByParce.getContentPane().setLayout(itnfPriceByParceLayout);
        itnfPriceByParceLayout.setHorizontalGroup(
            itnfPriceByParceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpPIBParceE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jpUpdatePriceE4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        itnfPriceByParceLayout.setVerticalGroup(
            itnfPriceByParceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(itnfPriceByParceLayout.createSequentialGroup()
                .addComponent(jpPIBParceE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpUpdatePriceE4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(itnfPriceByParce)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(itnfPriceByParce, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tbPriceByParceEMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbPriceByParceEMouseClicked
        // TODO add your handling code here:
        tbPriceByParceE.getSelectedRow();
        tfTypeParceIDE1.setText((String) tbPriceByParceE.getValueAt(tbPriceByParceE.getSelectedRow(), 1));
        tfTypeNameE1.setText((String) tbPriceByParceE.getValueAt(tbPriceByParceE.getSelectedRow(), 2));
        tfPriceOfTypeParceE1.setText(Float.toString((float) tbPriceByParceE.getValueAt(tbPriceByParceE.getSelectedRow(), 3)));
    }//GEN-LAST:event_tbPriceByParceEMouseClicked

    private void btEditE4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEditE4ActionPerformed
        // TODO add your handling code here:
        int result = JOptionPane.showConfirmDialog(this, "Do you want to edit the information?", "Information", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
        if (result == JOptionPane.YES_OPTION) {
            if ((a.UpdatePrice(tfTypeParceIDE1.getText(), tfTypeNameE1.getText(), Float.parseFloat(tfPriceOfTypeParceE1.getText()), "List_of_Parce", "TypeParceID", "TypeName", "PriceOfTypeParce")) == true) {
                a.ShowTable("STTP", "TypeParceID", "TypeName", "PriceOfTypeParce", "List_of_Parce", tbPriceByParceE);
            } else {
                JOptionPane.showMessageDialog(rootPane, "Data error");
            }
        }
    }//GEN-LAST:event_btEditE4ActionPerformed

    private void btResetE4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btResetE4ActionPerformed
        // TODO add your handling code here:
        a.ShowTable("STTP", "TypeParceID", "TypeName", "PriceOfTypeParce", "List_of_Parce", tbPriceByParceE);
        tfTypeParceIDE1.setText(s.CreateID("Prices_by_weight", "W"));
        tfTypeNameE1.setText(null);
        tfPriceOfTypeParceE1.setText(null);
    }//GEN-LAST:event_btResetE4ActionPerformed

    private void btExitE4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btExitE4ActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_btExitE4ActionPerformed

    private void btAddE5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAddE5ActionPerformed
        // TODO add your handling code here:
        try {
            try {
                // TODO add your handling code here:
                if (a.CheckIDPrice(tfTypeParceIDE1.getText(), "List_of_Parce") != -1) {
                    JOptionPane.showMessageDialog(this, "No add,ID already exists,You can to edit the information?");
                } else {
                    if ((a.InsertPrice(tfTypeParceIDE1.getText(), tfTypeNameE1.getText(), Float.parseFloat(tfPriceOfTypeParceE1.getText()), "List_of_Parce", "TypeParceID", "TypeName", "PriceOfTypeParce")) == true) {
                        a.ShowTable("STTP", "TypeParceID", "TypeName", "PriceOfTypeParce", "List_of_Parce", tbPriceByParceE);
                    } else {
                        JOptionPane.showMessageDialog(rootPane, "Error data enter");
                    }
                }
            } catch (SQLException ex) {
                Logger.getLogger(Prices_by_Parce.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Prices_by_Parce.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btAddE5ActionPerformed

    /**
     * @param args the command line arguments
     */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAddE5;
    private javax.swing.JButton btEditE4;
    private javax.swing.JButton btExitE4;
    private javax.swing.JButton btResetE4;
    private javax.swing.JInternalFrame itnfPriceByParce;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JPanel jpPIBParceE;
    private javax.swing.JPanel jpUpdatePriceE4;
    private javax.swing.JLabel lbPriceOfTypeParceE1;
    private javax.swing.JLabel lbTypeNameE1;
    private javax.swing.JLabel lbTypeParceIDSearchE1;
    private javax.swing.JTable tbPriceByParceE;
    private javax.swing.JTextField tfPriceOfTypeParceE1;
    private javax.swing.JTextField tfTypeNameE1;
    private javax.swing.JTextField tfTypeParceIDE1;
    // End of variables declaration//GEN-END:variables
}
